// pages/around/around.js
var amapFile = require('/lib/amap-wx.130.js');
var config = require('/lib/config.js');
const app = getApp()

Page({
  data: {
// tab导航栏
  tabs: ['青山绿水', '黑瓦白墙', ],
  itemWidth: 0,
  windowWidth: 0,
  tabIndex: 0,
  sliderLeft: 0,
  sliderOffset: 0,
  sliderOffsets: [],
  // 温度天气
    temperature:'',
    weather:'',
    //icon
    TabCur: 0,
    scrollLeft:0,
    cardCur: 0,
    gridCol: 4,
    geo_address:'',
    location:''
  },

/**
   * Tab导航栏
   */

  onLoad() {
    let that = this;
    // 计算
    wx.getSystemInfo({
      success: function(res) {
        // 每个item应占的宽度向上取整，限tab栏不会滑动的情况。
        let windowWidth = res.windowWidth;
        let itemWidth = Math.ceil(windowWidth / that.data.tabs.length);
        // 初始化每个项目的偏移量，存入数组
        let tempArr = [];
        for (let i in that.data.tabs) {
          tempArr.push(itemWidth * i);
        }

        // 32是两个字体（16px）的宽度。tab中字数不同的话需要调整...
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - 32) / 2,
          sliderOffsets: tempArr,
          sliderOffset: 0,
          itemWidth: itemWidth,
          windowWidth: windowWidth
        });
      }
    });
  },

  onShareAppMessage:function (e){
    return'';
    console.log(res.data);
  },

  onShareTimeline:function (e) {
    return'';
    console.log(res.data);
  },
  // 处理点击tab
  onTabClick(e) {
    let id = e.currentTarget.id;
    // 取新的偏移，完成transition和transform的参数
    let newOffset = this.data.sliderOffsets[id];
    this.setData({
      tabIndex: id,
      sliderOffset: newOffset
    })
  },

  // 处理swiper改变
  swiperChange(e) {
    this.setData({
      sliderOffset: this.data.sliderOffsets[e.detail.current],
      tabIndex: e.detail.current,
    })
  },

  //  处理手动滑动swiper-item.可以进一步对滚动条进行动画优化，但并不推荐。需要的话将注释放开即可
  swiperTran(e){
    // console.log("滑动tab中...")
  },

  // 滑动动画完毕后执行的方法(不管滑动是否完成切换)
  animationfinish(e){
    // console.log("动画执行完毕触发animationfinish")
  },

/**
   * Tab导航栏
   */


  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id-1)*60
    })
  },
  
  goTovillage: function(){
    wx.navigateTo({
      url:'/pages/village/village'
    })
  },
  goToculture2: function(){
    wx.navigateTo({
      url:'../culture2/culture2'
    })
  },

  goTosenior: function(){
    wx.navigateTo({
      url:'/pages/senior/senior'
    })
  },
  goTofood: function(){
    wx.navigateTo({
      url:'/pages/food/food'
    })
  },
  goTomeituan: function(){
    wx.navigateToMiniProgram({
      appId: 'wx4fa555703dced95c',
      extraData: {
        foo: 'bar'
      },
      envVersion: 'develop',
    })
  },
    onLoad:function() {
      var self = this;
      var myAmapFun = new amapFile.AMapWX({key: "04690d6167e1ac044bef1f45a67c7eca"});
      wx.request({
        url: 'https://restapi.amap.com/v3/weather/weatherInfo',
        data:{
          'key': 'a4c9ffeb014fe82b6a00711eaaf0270c',
          'city': '341023',
          'extensions': 'base'
        },
        header:{
          'content-type': 'application/json'
        },
        success:function(res){
          // console.log(res.data);
          self.setData({
            weather: res.data.lives[0].weather,
            temperature: res.data.lives[0].temperature,
          })
        }
      })
      // 初始化towerSwiper 传已有的数组名即可
    },


  /**
   *Tab导航栏
   */
  goTosenior1: function(){
    wx.navigateTo({
      url:'../senior1/senior1'
    })
  },
  goTosenior2: function(){
    wx.navigateTo({
      url:'../senior2/senior2'
    })
  },
  goTosenior3: function(){
    wx.navigateTo({
      url:'../senior3/senior3'
    })
  },
  goTosenior4: function(){
    wx.navigateTo({
      url:'../senior4/senior4'
    })
  },
  goTosenior5: function(){
    wx.navigateTo({
      url:'../senior5/senior5'
    })
  },
  goTosenior6: function(){
    wx.navigateTo({
      url:'../senior6/senior6'
    })
  },
  goTosenior7: function(){
    wx.navigateTo({
      url:'../senior7/senior7'
    })
  },
  goTosenior8: function(){
    wx.navigateTo({
      url:'../senior8/senior8'
    })
  },
  goTosenior9: function(){
    wx.navigateTo({
      url:'../senior9/senior9'
    })
  },
  goTosenior10: function(){
    wx.navigateTo({
      url:'../senior10/senior10'
    })
  },
  goTosenior11: function(){
    wx.navigateTo({
      url:'../senior11/senior11'
    })
  },
  goTosenior12: function(){
    wx.navigateTo({
      url:'../senior12/senior12'
    })
  },
  goTosenior13: function(){
    wx.navigateTo({
      url:'../senior13/senior13'
    })
  },
  goTosenior14: function(){
    wx.navigateTo({
      url:'../senior14/senior14'
    })
  },
  goTosenior15: function(){
    wx.navigateTo({
      url:'../senior15/senior15'
    })
  },
  goTosenior15: function(){
    wx.navigateTo({
      url:'../senior15/senior15'
    })
  },
  goTosenior16: function(){
    wx.navigateTo({
      url:'../senior16/senior16'
    })
  },
  goTosenior17: function(){
    wx.navigateTo({
      url:'../senior17/senior17'
    })
  },
  goTosenior18: function(){
    wx.navigateTo({
      url:'../senior18/senior18'
    })
  },
  goTosenior19: function(){
    wx.navigateTo({
      url:'../senior19/senior19'
    })
  },

  goTomweather: function(){
    wx.navigateTo({
      url:'../mweather/mweather'
    })
  },
/**
   *Tab导航栏
   */


  
    goToTalkPage:function(param){
        wx.navigateTo({
            url: 'pages/culture/culture.wxml'
          })
    },
   
    DotStyle(e) {
      this.setData({
        DotStyle: e.detail.value
      })
    },
    // cardSwiper
    cardSwiper(e) {
      this.setData({
        cardCur: e.detail.current
      })
    },

  
    
    })
